﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_UptBkcdt : System.Web.UI.Page
{
    private string dtnum = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        dtnum = Request.QueryString["Dtnum"];
        if (!IsPostBack)
        {
            btnUpt.Attributes.Add("onclick", "javascript:if(confirm('" + "确认无误，并修改么？" + "')== false) return false;");
            DataSet ds1 = BLLFactory.CreateBkcdtBLL().Select(dtnum);
            if (ds1 == null)
                Response.Write(" <script   language=javascript> window.alert( '无此记录，请联系管理员！ ');</script> ");
            else
            {
                string num = ds1.Tables[0].Rows[0]["num"].ToString();
                txtNUM.Text = dtnum;
                txtNUM.Attributes["contentEditable"] = "false";
                DataSet ds2 = BLLFactory.CreateKcBLL().Select(num);
                txtKu.Text = ds2.Tables[0].Rows[0]["ku"].ToString();
                txtKu.Attributes["contentEditable"] = "false";
                txtBanzu.Text = ds1.Tables[0].Rows[0]["banzu"].ToString();
                txtBanzu.Attributes["contentEditable"] = "false";
                txtTianbao.Text = ds1.Tables[0].Rows[0]["tianbao"].ToString();
                txtTianbao.Attributes["contentEditable"] = "false";
                txtPinzhong.Text = ds2.Tables[0].Rows[0]["pinzhong"].ToString();
                txtPinzhong.Attributes["contentEditable"] = "false";
                txtGuige.Text = ds2.Tables[0].Rows[0]["guige"].ToString();
                txtGuige.Attributes["contentEditable"] = "false";
                txtKN.Text = ds1.Tables[0].Rows[0]["kn"].ToString();
                txtKNDC.Text = ds1.Tables[0].Rows[0]["kndc"].ToString();
                txtKNFDC.Text = ds1.Tables[0].Rows[0]["knfdc"].ToString();
                txtDK.Text = ds1.Tables[0].Rows[0]["dk"].ToString();
                txtDKDC.Text = ds1.Tables[0].Rows[0]["dkdc"].ToString();
                txtDKFDC.Text = ds1.Tables[0].Rows[0]["dkfdc"].ToString();
            }

        }
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        int f = BLLFactory.CreateBkcdtBLL().Del(dtnum);
        if (f >= 1)
            Response.Write(" <script   language=javascript> window.alert( ' 删除成功！ ');</script> ");
        Response.Redirect("BKCDTJL.aspx");
    }
    protected void btnUpt_Click(object sender, EventArgs e)
    {
        if (txtKN.Text.ToString() != "" || txtDK.Text.ToString() != "")
        {
            decimal kn = Convert.ToDecimal(txtKN.Text.ToString());
            decimal dc = Convert.ToDecimal(txtKNDC.Text.ToString());
            decimal fdc = Convert.ToDecimal(txtKNFDC.Text.ToString());
            decimal dk = Convert.ToDecimal(txtDK.Text.ToString());
            decimal dkdc = Convert.ToDecimal(txtDKDC.Text.ToString());
            decimal dkfdc = Convert.ToDecimal(txtDKFDC.Text.ToString());
            if (kn != (dc + fdc))
                Response.Write(" <script   language=javascript> window.alert( ' 库内、库内定尺、库内非定尺数量不正确！ ');</script> ");
            else if (dk != (dkdc + dkfdc))
                Response.Write(" <script   language=javascript> window.alert( ' 东库、东库定尺、东库非定尺数量不正确！ ');</script> ");
            else
            {
                int f = BLLFactory.CreateBkcdtBLL().Update(dtnum, kn, dc, fdc, dk, dkdc, dkfdc);
                if (f >= 1)
                    Response.Write(" <script   language=javascript> window.alert( ' 修改成功！ ');</script> ");
            }
        }
        else
        {
            decimal dc = Convert.ToDecimal(txtKNDC.Text.ToString());
            decimal fdc = Convert.ToDecimal(txtKNFDC.Text.ToString());
            decimal dkdc = Convert.ToDecimal(txtDKDC.Text.ToString());
            decimal dkfdc = Convert.ToDecimal(txtDKFDC.Text.ToString());
            if (dc != 0 || fdc != 0 || dkdc != 0 || dkfdc != 0)
                Response.Write(" <script   language=javascript> window.alert( ' 库内定尺、库内非定尺、东库定尺、东库非定尺数量不正确！ ');</script> ");
            else
            {
                int f = BLLFactory.CreateBkcdtBLL().Update(dtnum, 0, 0, 0, 0, 0, 0);
                if (f >= 1)
                    Response.Write(" <script   language=javascript> window.alert( ' 修改成功！ ');</script> ");
            }
        }
        

        Response.Redirect("BKCDTJL.aspx");
    }
}
